package pers.xuehongyan.useat.server.manager;

import org.springframework.stereotype.Component;
import pers.xuehongyan.useat.server.enity.Machine;
import pers.xuehongyan.useat.server.exception.machine.MachineNotFoundException;
import pers.xuehongyan.useat.server.mapper.MachineMapper;

import javax.annotation.Resource;

/**
 * @author xuehongyan
 */
@Component
public class MachineManager {
    @Resource
    MachineMapper machineMapper;

    public Machine getMachineById(Integer id) throws MachineNotFoundException {
        Machine machine = machineMapper.selectById(id);
        if(machine == null) {
            throw new MachineNotFoundException();
        }
        return machine;
    }

    public void create(Machine machine) {
        machineMapper.insert(machine);
    }

    public void update(Machine machine) {
        machineMapper.updateById(machine);
    }
}
